package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐jiek")
@Slf4j
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    @PostMapping
    @ApiOperation("新增套餐")
    @CacheEvict(cacheNames = "setmealCache",key = "setmealDTO.categoryId")
    public Result sava(@RequestBody SetmealDTO setmealDTO){
        setmealService.save(setmealDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("套餐的分页查询")
    public Result<PageResult> select( SetmealPageQueryDTO setmealPageQueryDTO){
    PageResult pageResult = setmealService.select(setmealPageQueryDTO);
    return Result.success(pageResult);
    }
/*
根据id查询
* */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getBid(@PathVariable Long id){
        log.info("查询id是：{}",id);
        SetmealVO setmealVO = setmealService.getBid(id);
        return Result.success(setmealVO);
    }
    /*
    * 根据id修改套餐
    * */
@PutMapping
    @ApiOperation("根据id修改套餐")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<SetmealVO> uodate(@RequestBody SetmealDTO setmealDTO){
    log.info("修改id是：{}",setmealDTO.getId());
    setmealService.Update(setmealDTO);
    return Result.success();
}
/*
* 起售停售
* */
    @PostMapping("/status/{status}")
    @ApiOperation("修改起售状态")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public  Result updateStaus(@PathVariable Integer status,long id){
        log.info("状态码是：{}",status);
        setmealService.statusupdate(status,id);
        return Result.success();
    }
/*
* 根据id删除套餐
* */
    @DeleteMapping()
    @ApiOperation("根据id删除套餐")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除的id是：{}",ids);
        setmealService.deleteBid(ids);
        return Result.success();
    }
}
